﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;
using Newtonsoft.Json;
namespace ProjectStudy.Ajax
{
    /// <summary>
    /// 二级联动 的摘要说明
    /// </summary>
    public class 二级联动 : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            
            //判断是否登录
            //if(sysSession.UserId!=null)
            string action = context.Request.Params["action"];
            switch (action)
            {
                case "GetPro": GetPro(context);
                    break;
                case "GetCity": GetCity(context);
                    break;
            }

        }

        private void GetPro(HttpContext context)
        {
            string sql = @"select ProvinceName from Province";
            DataTable dt = DBAccess.ExecuteDataTable(sql);
            context.Response.Write(JsonConvert.SerializeObject(dt));
        }

        private void GetCity(HttpContext context)
        {
            string ProvinceName = context.Request["ProvinceName"];
            string sql = @"select CityName from City where ProvinceName=@ProvinceName";
            SqlParameter ps = new SqlParameter("@ProvinceName",ProvinceName);
            DataTable dt = DBAccess.ExecuteDataTable(sql, ps);
            context.Response.Write(JsonConvert.SerializeObject(dt));
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}